package com.zmn.oms.services.impl.tipsconfig;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.oms.model.entity.tipsconfig.PictureTipsConfig;
import com.zmn.oms.model.entity.tipsconfig.PictureTipsConfigQuery;
import com.zmn.oms.persistence.interfaces.tipsconfig.PictureTipsConfigDao;
import com.zmn.oms.services.interfaces.tipsconfig.PictureTipsConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 基础接口实现类
 *
 * @author weilai
 * @since 2022-08-02 14:11:21
 **/
@Slf4j
@Service
public class PictureTipsConfigServiceImpl implements PictureTipsConfigService {

    private static final String TAG = "基础服务接口";

    @Resource
    private PictureTipsConfigDao pictureTipsConfigDao;
    private Integer id;

    /**
     * 描述: 根据id查询数据
     *
     * @param id id
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public PictureTipsConfig findById(Integer id) {
        this.id = id;

        if (Objects.isNull(id)) {
            log.error("[{}],根据id查询数据id为null", TAG);
            return null;
        }
        return pictureTipsConfigDao.findById(id);
    }

    @Override
    public Integer findMaxSort(Integer servCategId, Integer categOneId, Integer categId) {
        if (NumberUtil.isNullOrZero(servCategId) || NumberUtil.isNullOrZero(categOneId) || NumberUtil.isNullOrZero(categId)) {
            log.error("[{}],根据id查询数据id为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.findMaxSort(servCategId,categOneId,categId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public List<PictureTipsConfig> listPageByQuery(PictureTipsConfigQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        Integer count = countByQuery(query);
        query.setTotalCount(count);
        return pictureTipsConfigDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public List<PictureTipsConfig> listByQuery(PictureTipsConfigQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }

        return pictureTipsConfigDao.listByQuery(query);
    }

    @Override
    public List<PictureTipsConfig> listServCategory(List<Integer> listServCategory) {
        if (CollectionUtil.isNullOrEmpty(listServCategory)) {
            return Collections.emptyList();
        }
        return pictureTipsConfigDao.listServCategory(listServCategory);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public Integer countByQuery(PictureTipsConfigQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param pictureTipsConfig 待修改数据
     * @return java.lang.Integer
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public Integer updateByKey(PictureTipsConfig pictureTipsConfig) {

        if (Objects.isNull(pictureTipsConfig.getId())) {
            log.error("[{}],根据id修改数据,pictureTipsConfig为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.updateByKey(pictureTipsConfig);
    }

    /**
     * 描述: 根据id修改排序id为必传
     *
     * @param sortModifyBO 待修改数据
     * @return java.lang.Integer
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public Integer updateSortByKey(PictureTipsConfig sortModifyBO) {
        if (NumberUtil.isNullOrZero(sortModifyBO.getId())) {
            log.error("[{}],根据id修改数据,id为null", TAG);
        }
        int updateCount = pictureTipsConfigDao.updateSortByKey(sortModifyBO);
        return updateCount;
    }

    /**
     * 描述: 新增数据
     *
     * @param pictureTipsConfig 待新增数据
     * @return java.lang.Integer 主键key
     * @author weilai
     * @since 2022-08-02 14:11:21
     **/
    @Override
    public Integer insert(PictureTipsConfig pictureTipsConfig) {

        if (Objects.isNull(pictureTipsConfig)) {
            log.error("[{}],新增数据,pictureTipsConfig为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.insert(pictureTipsConfig);
    }

    @Override
    public void insertPictureTipsList(List<PictureTipsConfig> list) {
        if (CollectionUtil.isNullOrEmpty(list)) {
            log.error("[{}],新增数据,pictureTipsConfig为null", TAG);
            return;
        }
        pictureTipsConfigDao.insertPictureTipsList(list);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param id
     * @return: 执行结果码
     * @auther: weilai
     * @since: 2022-08-02 14:11:21
     */
    @Override
    public Integer deleteByKey(Integer id) {

        if (Objects.isNull(id)) {
            log.error("[{}],根据id删除数据,id为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.deleteByKey(id);
    }

    @Override
    public Integer deleteByKeys(List<Integer> delListId) {
        if (CollectionUtil.isNullOrEmpty(delListId)) {
            log.error("[{}],根据id删除数据,id为null", TAG);
            return GlobalConsts.NONE;
        }
        return pictureTipsConfigDao.deleteByKeys(delListId);
    }

}